<?php
namespace app\ice\controller;
use think\Controller;
use think\Validate;
use think\Db;
use org\BaiduMap;
use think\Model;
use think\Loader;
use org\HMongodb;
// use app\common\logic\GoodsPromFactory;
// use app\common\model\SpecGoodsPrice;
use think\Page;

class Goods extends Init
{
    protected function _initialize()
    {
        
        parent::_initialize();
        $this->GoodsModel = Loader::model('Goods');
        // $this->GoodsLogicModel = Loader::model('GoodsLogic');
    }
    //获取商品列表
    public function goodsList(){
        $param = input('post.');
        $result = $this->validate($param, 'GoodsValidate.category');
            if (true !== $result) {
                return ['code'=>400,'message'=>$result,'data'=>[],'status'=>false];
            }
        $page = isset($param['page']) ? ($param['page'] == false ? 1 : $param['page'] ) : 1;
        $orll_page = isset($param['pageSize']) ? ($param['pageSize'] == false ? config('paginate.list_rows'): $param['pageSize'] ) : config('paginate.list_rows');
        if($param['prom_type'] == 3){
            $data = $this->GoodsModel->getPromotionGoods($param);
        }else{
            $data = $this->GoodsModel->getGoodsListData($param);
        }
        if($data){
            if($data){
                return ['data' => $data, 'code' => 200, 'message' => '列表显示成功', 'status' => true];
            }else{
                return ['data' => $data, 'code' => 400, 'message' => '没有更多的商品了', 'status' => false];
            }
        }else{
                return ['data' => [], 'code' => 400, 'message' => '暂时没有可售的商品', 'status' => false];
        }
    }
    
    public function detail(){
        $param = input('post.');
        // $result = $this->validate($param, 'GoodsValidate.goods');
        //     if (true !== $result) {
        //         return ['code'=>400,'message'=>$result,'data'=>[],'status'=>false];
        //     }
        $goods_id = $param['id'];
        $res = $this->GoodsModel->getGoodsDetail($param);
        return ['code'=>200,'message'=>'成功','data'=>$res,'status'=>true];
    }

    public function reputation(){
        $param = input('post.');
        $res = $this->GoodsModel->getReputations($param['goodsId']);
        return ['code'=>200,'message'=>'成功','data'=>$res,'status'=>true];
    }
    
    public function goodsSpecPrice(){
        $param = input('post.');
        $result = $this->validate($param, 'GoodsValidate.item');
            if (true !== $result) {
                return ['code'=>400,'message'=>$result,'data'=>[],'status'=>false];
            }
            $goods_id = $param['goods_id'];
        $res = $this->GoodsModel->getSpecGoodsPrice($param);
        if(count($res) > 0){
            return ['code'=>200,'message'=>'成功','data'=>$res,'status'=>true];
        }else{
            return ['code'=>400,'message'=>'没有该规格','data'=>$res,'status'=>false];
        }
    }
}